package com.hasbei.controller;

import com.hasbei.service.ITopicService;
import com.hasbei.vo.ResultVO;
import com.hasbei.vo.TopicVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping(produces = {"application/json;charset=UTF-8"})
@Slf4j
@CrossOrigin
public class TopicController {

    @Autowired
    private ITopicService iTopicService;

    /**
     * 查询所有主题信息
     * @return
     */
    @RequestMapping("/query/all")
    public ResultVO<List<TopicVO>> topicList(){
        ResultVO<List<TopicVO>> resultVO = new ResultVO();
        resultVO.setBody(iTopicService.findTopicList());
        return resultVO;
    }

    /**
     * 删除主题信息
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public int delTopic(@PathVariable Long id) {
        log.info("删除查询标题id={}",id);
        return iTopicService.delTopic(id);
    }

    /**
     *  根据id查询主题信息
     * @param id
     * @return
     */
    @GetMapping("/query/topicById/{id}")
    public ResultVO<TopicVO> getTopicById(@PathVariable Long id) {
        log.info("开始查询标题id={}",id);
        ResultVO<TopicVO> resultVO = new ResultVO();
        resultVO.setBody(iTopicService.findTopicById(id));
        return resultVO;
    }

    /**
     * 新增主题信息
     * @param topicVO
     * @return
     */
    @PostMapping("/add")
    public int addTopic(TopicVO topicVO){
        log.info("新增的标题={}",topicVO);
        return iTopicService.addTopic(topicVO);
    }

    /**
     * 修改主题信息
     * @return
     */
    @PostMapping("/alt")
    public int altTopic(TopicVO topicVO){
        log.info("修改后的标题={}",topicVO);
        return iTopicService.alterTopic(topicVO);
    }

    /**
     * 查询问题主题信息集合
     * @return
     */
    @RequestMapping("/query/iss")
    public ResultVO<List<TopicVO>> issueTopicList(){
        ResultVO<List<TopicVO>> resultVO = new ResultVO();
        resultVO.setBody(iTopicService.findIssueTopicList());
        return resultVO;
    }

    /**
     * 查询咨询主题信息集合
     * @return
     */
    @RequestMapping("/query/cons")
    public ResultVO<List<TopicVO>> consultTopicList(){
        ResultVO<List<TopicVO>> resultVO = new ResultVO();
        resultVO.setBody(iTopicService.findConsultTopicList());
        return resultVO;
    }
<<<<<<< Updated upstream
=======

>>>>>>> Stashed changes
}
